home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 26.zip
/
BS1 part 26
/
The Director Toolkit v1.0.adf
/
Programs
/
SineTable
/
docs
< prev
next >
Wrap
Text File
|
1987-02-25
|
3KB
|
80 lines
|c7|f2|t1Pie Chart and Sine Table|c3|f1|t0
The examples in this directory demonstrate the use of integer based
sine and cosine functions. There are two demos, a simple routine to
graph the sine and cosine functions on the screen, and a pie chart
example that uses sine and cosine to determine where the pie wedges
lie.|r1
The SineCosDemo script demonstrates the basic setup of the sine table
and the basic use. Since the Director only supports integer arithmetic
and sine values range between |c7+1|c3 and |c7-1|c3, the sine values are
scaled |c7x10000|c3 providing |c74|c3 significant digits. You must
remember when using
the sine values that they are multiplied by |c710000|c3|-.|r1
|e
To use the sine cosine routines, set the variable |c7"deg"|c3 equal to the
value you wish to find the sine or cosine of in degrees. Then do
a |c7GOSUB 5000|c3 for the sine, or |c7GOSUB 5010|c3 for the cosine. The
sine will be returned in the variable |c7sin|c3 and cosine in the variable
|c7cos|c3|-.|r1
You will generally
achieve the best accuracy when using these routines if you do your
multiplies first, then your divides. This preserves digits of accuracy
longer through your calculations.
|e
For example, if you want to determine
|c7200*sin(x)|c3|-, if you compute it like this:|r1
|c7|+8deg=x|r1
|+8gosub 5000 :rem get the sine|r1
|+8ans=(200*sin)/10000 :rem multiply before dividing|c3|r1
Clearly, if you were to divide by |c710000|c3 first, you would reduce your
sin value to either |c7-1, 0, or 1|c3 losing all precision in your
calculation.
|e
This rule of multiplication first holds through most related calculations,
and you can minimize any truncation errors by rounding like this:|r1
|c7|+8ans=(200*sin+5000)/10000|c3|r1
To round, add 1/2 of your divisor to the numerator in the division.|r1
|e
The Pie Chart demo uses the sine and cosine routines to locate the
various positions of the pie wedges. The |c7360|c3 degrees of a circle
can be defined graphically as:|r1
|c7|+8x = xcenter+sin(deg)*radius|r1
|+8y = ycenter+cos(deg)*radius|c3|r1
in mathematical terms. The Director version of the above calculation
is:|r1
|c7|+4deg = 0 :rem set this to desired degree point on the circle.|r1
|+4gosub 5000|r1
|+4gosub 5010|r1
|+4x = xcenter+(sin*radius+5000)/10000|r1
|+4y = ycenter+(cos*radius+5000)/10000|c3|r1
|e
And, due to the fact that in the Amiga's coordinate system, the |c7Y|c3
coordinate
is inverted (larger |c7Y|c3 goes down instead of up), you can flip the
|c7Y|c3 axis like this:|r1
|c7|+8y = ycenter-(cos*radius+5000)/10000|c3|r1
This gives you |c70|c3 degrees on the circle at the top of the circle
(instead of the bottom).|r1
The Pie Chart demo is designed so that you can easily change the size
and center position of the pie chart, and insert your own data and
labelling. It can be adapted as a general purpose pie chart generator
if desired.